<template>
  <div class="index">
    <div class="addInformation">
      <!-- <el-select class="btn" @change='changeSelect' v-model="params.newsType" placeholder="咨询分类">
        <el-option 
            v-for="item in options" 
            :key="item.value" 
            :label="item.text" 
            :value="item.value">
        </el-option>
      </el-select> -->
    </div>

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="反馈ID"></el-table-column>
      <el-table-column prop="name" label="姓名"></el-table-column>
      <el-table-column prop="mobile" label="手机号"></el-table-column>
      <el-table-column prop="content" label="留言内容"></el-table-column>
      <el-table-column label="留言时间">
          <template slot-scope="scope">
              <span>{{scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}')}}</span>
          </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button v-if="scope.row.handleTime === 0" @click="handle(scope.row.id)" type="text" size="mini">处理</el-button>
          <span v-if="scope.row.handleTime > 0" class='hasHandle'>已处理</span>  
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="pagination"
      background
      @current-change="handleCurrentChange"
      layout="prev, pager, next"
      :total="total"
    ></el-pagination>
  </div>
</template>


<script>
import { ajax } from "@/api";
import { parseTime } from "@/utils";
import { getToken } from "@/utils/auth";
export default {
  name: "index",
  data() {
    return {
      tableData: [],
      total: 0,
      // options: [
      //   {
      //     text: "资讯类",
      //     value: "normal"
      //   },
      //   // {
      //   //   text: "公告类",
      //   //   value: "notice"
      //   // },
      //   // {
      //   //   text: "连接类",
      //   //   value: "hidden"
      //   // }
      // ],
      params: {
        start: 0,
        limit: 10,
        token: getToken()
      },
      handleParams:{
          targetId:'',
          token:getToken()
      }
    };
  },
  methods: {
    //用户反馈列表
    getList() {
      ajax("feedbacks", this.params).then(res => {
        if(res.data.status){
            this.tableData = res.data.data;
            this.total = res.data.total;
        }else{
            this.$message.error(res.data.message);
        }
      });
    },
    changeSelect(){
        this.getList();
    },
    handleCurrentChange(val) {
      this.params.start = (val - 1) * this.params.limit;
      this.getList();
    },
    //处理反馈
    handle(id){
      this.handleParams.targetId = id;
      ajax("feedbackHandle", this.handleParams).then(res => {
        console.log(res);
        if(res.data.code === 200){
          this.$message.success(res.data.message);
          setTimeout(() => {
            location.reload();
          },100);
        }else{
          this.$message.error(res.data.message);
        }
      });
    }
  },
  mounted() {
    this.getList();
  }
};
</script>


<style lang="less" scoped>
.index {
  padding: 1rem;
  .addInformation {
    margin: 1rem 0;
    .btn{
        margin-right: 1rem;
    }
  }

  .hasHandle{
    font-size: 12px;
  }


  .del {
    color: red;
  }
  .pagination{
    text-align: right;
    margin: 1rem 0;
  }
}
</style>
